
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Universidad del Valle de Guatemala
 * CC2003 Algoritmos y Estructuras de Datos
 * Proyecto 2: Cliente-Servidor
 * @version 29 Noviembre, 2009
 * Integrantes:
 *      @author Héctor Hurtarte, José García, Asucena
 **/
class AdministratorThread extends Thread{
    private Boolean listening;
    private ArrayList<Request> tasks;
    public AdministratorThread(ArrayList<Request> tasks, Boolean listening) {
        this.listening=listening;
        this.tasks=tasks;
    }
    public void run(){
        Scanner scan=new Scanner(System.in);
        String messaje=scan.next();
        while(true){
            if(messaje.equals("monitor")){
                tasksLog();
            }
            messaje=scan.next();
        }
    }
    public void tasksLog(){
        String st="";
        synchronized(tasks){
                for (int a=0;a<tasks.size();a++){
                    if(tasks.get(a).messaje().equals("LOG")){
                        tasks.remove(a);
                    }if(a<tasks.size()){
                        st=st+"Request "+a+": " +tasks.get(a).toString()+"\n";
                    }
                }
                if(tasks.size()==0){
                    st="Tasks queue is empty.\n";
                }
        System.out.println(st);
        }
    }

}
